﻿<style>


    .jg-right {
        padding-top: 20px;
    }
</style>
<div style="display:none">
    <div class="jg-left pull-left ft14">
        <p class="mb10 ft16 padding20 " style="border-bottom: 1px solid #e5e5e5;">
            <i class="iconfont icon-tuodong  mr5"></i>数据源列表
            <i class="iconfont icon-jiahao ft12 pull-right mt5 pl20" ms-click="AddDSource()" title="添加数据源" style="cursor: pointer;color:black"></i>
        </p>
        <ul class="jg-list-box">
            <!--<li>
                <div class="jg-item" style="padding: 0px;">
                    <b class="ml15">
                        <i class="iconfont icon-peizhishujuyuan"></i>
                        <span class="jg-name">自定义表单</span><i class="jg-number ft12 c999">（本地数据源--待开发）</i>
                    </b>
                </div>
            </li>-->
            <li ms-repeat-item="DataSourceS" ms-click="selDSource(item)">
                <div class="jg-item" ms-class="active:item.Name==SelDSourceItem.Name" style="padding: 0px;">
                    <b class="ml15">
                        <i class="iconfont icon-peizhishujuyuan" ms-class-1="text-danger:item.Attach=='1'" ms-class-2="text-success:item.Attach=='0'"></i>
                        <span class="jg-name">{{item.Name}}</span><i class="jg-number ft12 c999">（{{item.DBType}}）</i>
                    </b>
                </div>
            </li>
        </ul>
    </div>
    <div class="jg-right pt20 ft14">
        <div class="btn-add">
            <button type="button" class="btn btn-info" ms-click="DelDSource()"><i class="iconfont icon-shanchu ft14 mr5"></i>删除数据源</button>
            <button type="button" class="btn btn-info" ms-click="EditDSource()"><i class="iconfont icon-bianji ft14 mr5"></i>修改数据源</button>
        </div>
        <!-- 机构管理详情 -->
        <div class="jg-cont ft14">
            <div class=" ml15" style="position: relative">
                <a class="c-default dropdown-toggle ft16" data-toggle="dropdown">
                    <i class="iconfont icon-qunfengshangjiaxiangqing c-default mr5"></i>数据源详情
                </a>
            </div>
            <div class="detail-con">

                <div class="detail-item">
                    <span class="item-tit">数据源名称：</span>
                    <div class="item-con">{{SelDSourceItem.Name}}</div>
                </div>
                <div class="detail-item">
                    <span class="item-tit">数据源类型：</span>
                    <div class="item-con">{{SelDSourceItem.DBType}}</div>
                </div>

            </div>
        </div>
        <!-- 分割线 -->
        <div class="add-tab ft14 tc"></div>

        <div class="default-tab ft14 pt20 table-responsive" style="max-height:600px">
            <table class="table table-striped  table-hover" id="branchTab">
                <thead>
                    <tr>
                        <th class="tc" style="width: 80px;">
                            序号
                        </th>
                        <th>表名称</th>
                        <th>描述</th>
                        <th style="width: 120px;">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ms-repeat-item="VIEWS">
                        <td class="tc">
                            {{$index+1}}
                        </td>
                        <td class="lk">
                            {{item.Name}}
                        </td>
                        <td>
                            {{item.Description}}
                        </td>
                        <td>
                            <span class="btn-click">
                                <a class="cz-btn ft18 bj-color tip" data-toggle="tooltip" title="生成数据集" ms-click="AddDSet(item)">
                                    <i class="iconfont icon-shujuji"></i>
                                </a>
                                <!--<a class="cz-btn ft18 sc-color tip" data-toggle="tooltip" title="查看详情" >
                                    <i class="iconfont icon-qunfengshangjiaxiangqing"></i>
                                </a>-->
                            </span>
                        </td>
                    </tr>
                </tbody>
                <tfoot ms-if="VIEWS.length==0">
                    <tr>
                        <td colspan="4">暂无数据</td>
                    </tr>
                </tfoot>
            </table>
        </div>

    </div>

</div>
<div ms-controller="DSINDEX">
    <!-- 添加按钮 -->
    <div class="btn-add">
        <button type="button" class="btn btn-info btn-lg" ms-click="Add()"><i class="iconfont icon-jiahao ft12 mr5"></i>新建数据源</button>
    </div>
    <!-- 按条件选择 -->
    <div class="tab-filter-type">
        <div class="oh">
            <h5 class="pull-left tr">全部类型：</h5>
            <ul class="tab-type ft14">
                <li><span class="active">全部</span></li>
                <!--<li><span>SQLSERVER</span></li>
                <li><span>MYSQL</span></li>-->
            </ul>
        </div>
    </div>
    <!-- 表格 -->
    <div class="default-tab ft14 pt20 hover-btn">
        <table class="table table-striped table-responsive table-hover">
            <thead>
                <tr>
                    <th class="tc width-70">
                        序号
                    </th>
                    <th>名称</th>
                    <th>数据源类型</th>
                    <th>IP</th>
                    <th>端口</th>
                    <th>数据库名称</th>
                    <th>登录名</th>
                    <th>创建人</th>
                    <th>创建时间</th>
                    <th width="10%">操作</th>
                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-item="DataSourceS">
                    <td class="tc">
                        {{$index+1}}
                    </td>
                    <td class="lk">{{item.Name}}</td>
                    <td>{{item.DBType}}</td>
                    <td>{{item.DBIP}}</td>
                    <td>{{item.Port}}</td>
                    <td>{{item.DBName}}</td>
                    <td>{{item.DBUser}}</td>
                    <td>{{item.CRUser}}</td>
                    <td>{{item.CRDate|date("yyyy-MM-dd HH:mm")}}</td>
                    <td>
                        <span class="btn-click">
                            <a class="cz-btn ft18 bj-color tip" data-toggle="tooltip" title="编辑" ms-click="edit(item)" >
                                <i class="iconfont icon-bianji"></i>
                            </a>
                            <a class="cz-btn ft18 sc-color tip" data-toggle="tooltip" title="删除" ms-click="DelDSource(item)">
                                <i class="iconfont icon-shanchu"></i>
                            </a>
                        </span>
                    </td>
                </tr>
            </tbody>

        </table>




    </div>

    <div class="modal fade" id="DSModal" role="dialog">
        <div class="modal-dialog" role="document" style="width: 600px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">编辑数据源</h4>
                </div>
                <div class="modal-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label for="branchName" class="col-xs-3 control-label text-right">数据源显示名称</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" ms-duplex="SelDSourceItem.Name" placeholder="数据源名称" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label text-right">数据源类型</label>
                            <div class="col-xs-7">
                                <select id="roleType" class="form-control" ms-duplex="SelDSourceItem.DBType">
                                    <option value="SQLSERVER">SQLSERVER</option>
                                    <option value="MYSQL">MYSQL</option>

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label text-right">IP</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" ms-duplex="SelDSourceItem.DBIP" placeholder="数据源IP" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label text-right">端口</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" ms-duplex="SelDSourceItem.Port" placeholder="端口" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label text-right">数据库名</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" ms-duplex="SelDSourceItem.DBName" placeholder="数据库名" />
                            </div>
                        </div>


                        <!--<div class="form-group">
                            <label class="col-xs-3 control-label text-right">架构</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" ms-duplex="SelDSourceItem.Schema" placeholder="架构" />
                            </div>
                        </div>-->
                        <div class="form-group">
                            <label class="col-xs-3 control-label text-right">登录名</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" ms-duplex="SelDSourceItem.DBUser" placeholder="登录名" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-3 control-label text-right">密码</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" ms-duplex="SelDSourceItem.DBPwd" placeholder="密码" />
                            </div>
                        </div>
                        <!--<div class="form-group">
                            <label for="branchDesc" class="col-xs-3 control-label text-right">数据源描述</label>
                            <div class="col-xs-7">
                                <textarea class="form-control" ms-duplex="SelDSourceItem.Remark" placeholder="请输入数据源描述"></textarea>
                            </div>
                        </div>-->

                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-info" ms-click="TestCon()">连接测试</button>

                    <button type="button" class="btn btn-success" id="conaddForder" ms-click="ConfirmData()">确&nbsp;&nbsp;认</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var tempindex = avalon.define({
        $id: "DSINDEX",
        DataSourceS: [],
        VIEWS: [],
        SelDSourceItem: {},
        selDSource: function (source) {
            tempindex.SelDSourceItem = {};
            tempindex.SelDSourceItem = source;
        },
        Add: function () {
            tempindex.SelDSourceItem = { Name: "", DBType: "SQLSERVER", DBIP: "", Port: "1433", DBName: "", Schema: "dbo", DBUser: "", DBPwd: "", ID: "0" };
            $('#DSModal').modal('show');
        },
        edit: function (item) {
            tempindex.SelDSourceItem = {};
            tempindex.SelDSourceItem = item.$model;
            $('#DSModal').modal('show');
        },
        ConfirmData: function () {
            $.getJSON('/api/Bll/ExeAction?Action=DATABI_ADDBIDBSOURCE', { P1: JSON.stringify(tempindex.SelDSourceItem.$model) }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    top.ComFunJS.winsuccess("操作成功");
                    $('#DSModal').modal('hide');
                    tempindex.InitWigetData();

                }
            })
        },
        DelDSource: function (item) {
            ComFunJS.winconfirm("删除数据源的同时同时会删除数据集,确认要删除吗", function () {
                $.getJSON('/api/Bll/ExeAction?Action=DATABI_DELBIDBSOURCE', { "P1": item.ID }, function (result) {
                    if (result.ErrorMsg == "") {
                        ComFunJS.winsuccess("删除成功");
                        model.refpage();
                    }
                })
            }, function () { })
        },
        AddDSet: function (DataSet) {
            $.getJSON('/api/Bll/ExeAction?Action=DATABI_ADDBISETLIST', { P1: tempindex.SelDSourceItem.ID, P2: DataSet.name, DsetName: DataSet.name }, function (resultData) {
                if (resultData.ErrorMsg == "") {
                    top.ComFunJS.winsuccess("操作成功");
                }
            })
        },
        TestCon: function () {
            $.getJSON('/api/Bll/ExeAction?Action=DATABI_TESTBIDBSOURCE', { P1: JSON.stringify(tempindex.SelDSourceItem.$model) }, function (resultData) {
                if (resultData.ErrorMsg == "" && resultData.Result == '1') {
                    top.ComFunJS.winsuccess("连接成功");
                }
            })
        },
        InitWigetData: function () {
            $('[data-toggle="tooltip"]').tooltip()
            $.getJSON('/api/Bll/ExeAction?Action=DATABI_GETBIDBSOURCELIST', {}, function (resultData) {
                if (resultData.Result.length > 0) {
                    tempindex.DataSourceS = resultData.Result;
                }
            })

        },
    });

    //# sourceURL=DSINDEX.js;
</script>
